local shot = Obstacle:addState("shot")

function shot:enteredState()
	print("entered obstacle state shot")
	self.velocity = 10
	self.accel = 500
	self.min_velocity = 100
	self.max_velocity = 700
	self.dest_x = game.player.x
	self.dest_y = game.player.y
	self.hit = false

	self.x, self.y = self:random_spawn()
	
end

function shot:random_spawn()

	local x_or_y = love.math.random()
	local x, y
	local which_side = love.math.random()

	local player = game.player
	local sw = love.window.getWidth()
	local sh = love.window.getHeight()
	if x_or_y > 0.5 then
		
		if which_side > 0.5 then
			x = player.x-sw/2
		else
			x = player.x+sw/2
		end
		y = player.y-love.math.random(sh*0.25, sh*0.75)
	else
		x = player.x-love.math.random(sw*0.25, sw*0.75)
		if which_side > 0.5 then
			y = player.y-sh/2
		else
			y = player.y+sh/2
		end
	end

	return x, y
end

function shot:update(dt)
	local moveX = self.x-self.dest_x
	local moveY = self.y-self.dest_y
	self.x = self.x-self.velocity*moveX*dt
	self.y = self.y-self.velocity*moveY*dt

end

function shot:on_collision(collider, direction)

	if collider.entity_type == "player" and self.hit == false then
		print("shot hit player")
		self.hit = true
		collider:damage(love.math.random(5,10))
	end
	--self:destroy()
end

function shot:exitedState()
	print("exited obstacle state shot")
end